import React, { useState, useEffect } from 'react';
import { connect } from 'umi';
import { Table } from 'antd';
import ViewDetail from './ViewDetail';

const columns = (setVisible, setArrangeCode) => [
    {
        title: '面试类型',
        dataIndex: 'interviewTypeValue',
        key: 'interviewTypeValue'
    },
    {
        title: '面试时间',
        dataIndex: 'interviewTime',
        key: 'interviewTime'
    },
    {
        title: '面试结果',
        dataIndex: 'interviewConclusionValue',
        key: 'interviewConclusionValue',
        render(text, record) {
            return <span>{record.interviewConclusionValue ? record.interviewConclusionValue : '--'}</span>;
        }
    },
    {
        title: '评分',
        dataIndex: 'interviewScore',
        key: 'interviewScore',
        render: text => {
            if (text || text === 0) {
                return `${text} 分`;
            }
            return '--';
        }
    },
    {
        title: '面试官',
        dataIndex: 'interviewEmployeeName',
        key: 'interviewEmployeeName'
    },
    {
        title: '招聘负责',
        dataIndex: 'interviewLeaderName',
        key: 'interviewLeaderName'
    },
    {
        title: '操作',
        dataIndex: '',
        key: '',
        render(text, record) {
            return (
                <div>
                    {record.isWatchRecord ? (
                        <a
                            onClick={e => {
                                e.preventDefault();
                                setArrangeCode(record.interviewArrangeCode);
                                setVisible(true);
                            }}
                        >
                            查看详情
                        </a>
                    ) : null}
                </div>
            );
        }
    }
];
const ViewRecord = ({ tableData, companyId = '', dispatch, filterRecord }) => {
    const { interviewResult } = filterRecord; // 面试结果弹框详情数据
    const [visible, setVisible] = useState(false); // 监听面试详情模态框
    const [arrangeCode, setArrangeCode] = useState(''); // 监听面试code发生变更
    // 请求面试结果
    useEffect(() => {
        if (visible) {
            dispatch({
                type: 'filterRecord/fetchInterviewResult',
                payload: {
                    arrangeCode
                }
            });
        }
    }, [visible]);
    return (
        <div>
            <Table dataSource={tableData} pagination={false} columns={columns(setVisible, setArrangeCode)} />
            <ViewDetail
                Visible={visible}
                DetailDate={interviewResult}
                companyId={companyId}
                // 关闭模态框
                disabled="true"
                onOk={() => {
                    setVisible(false);
                    dispatch({
                        type: 'filterRecord/save',
                        payload: {
                            interviewResult: []
                        }
                    });
                }}
                onCancel={() => {
                    setVisible(false);
                    dispatch({
                        type: 'filterRecord/save',
                        payload: {
                            interviewResult: []
                        }
                    });
                }}
            />
        </div>
    );
};
// export default ViewRecord;
export default connect(({ filterRecord, loading }) => ({
    filterRecord,
    loading
}))(ViewRecord);
